$(function() {
    $("#asignup").click(function() {
        loadRegistrationForm();
    });

    $('#bLogin').click(function() {
        login();
    });
});

function login() {
    var email = $('#inEmail').val();
    var password = $('#inPassword').val();

    if (!email) {
        showNotification({
            message: "Please type your email.",
            type: "error",
            autoClose: true,
            duration: 3
        });
    }
    
    if (!password) {
        showNotification({
            message: "Please type your password.",
            type: "error",
            autoClose: true,
            duration: 3
        });
    }

    $.post('/login', {email: email, password: password})
            .done(function(data) {
        if (data.toLowerCase() !== "login success") {
            showNotification({
                message: data,
                type: "error",
                autoClose: true,
                duration: 3
            });
        } else {
            window.location.href = "http://localhost:3000/";
        }       
    });
}

function loadRegistrationForm() {
    $("#divregister").dialog({
        height: 500,
        width: 400,
        modal: true,
        resizable: false
    });
}

function register() {
    var companyId;
    var user;
    
    user = {
        email: $('#inRegEmail'),
        companyid: companyId,
        firstname: $('#inRegEmail'),
        lastname: $('#inRegEmail'),
        role: 'user'
    };
}